<template>
	<view class="page" style="background-color: white;">
		<view class="swiper">
			<swiper class="swiper-view" circular @change="swiperChange" :autoplay="swiperConfig.autoplay"
				:interval="swiperConfig.interval" :duration="swiperConfig.duration">
				<swiper-item v-for="(v, k) in banner" :key="k" @tap="go(v.id)">
					<view class="swiper-item">
						<image :src="v.image"></image>
						<view class="swiper-item-title">
							<!-- <text>{{v.title}}</text> -->
							<!-- <text>{{v.title}} {{v.create_at}}</text> -->
						</view>
					</view>
				</swiper-item>
			</swiper>
			<view class="swiper-dots">
				<view v-for="(v, k) in list" :key="k"
					:class="'swiper-dots-item ' + (current === k ? 'swiper-dots-active' : '')"></view>
			</view>
		</view>

		<view class="article">
			<view class="article-item" v-for="(v, k) in article" :key="k" @tap="go(v.id)">
				<view class="article-item-image">
					<image :src="v.image"></image>
				</view>
				<view class="article-item-tilte">
					<text>{{v.title}}</text>
					<text>{{v.xtitle}} {{v.create_at}}</text>
				</view>
			</view>
		</view>
	</view>
	<xa-uv-bottom-tabbar />
</template>

<script>
	export default {
		data() {
			return {
				article: [],
				banner: [],
				swiperConfig: {
					autoplay: true,
					interval: 5000,
					duration: 500
				},
				current: 0, // 轮播图当前下标
				// 示例图片尺寸为 4:3
				list: [{
					title: '无芯片不“AI”——AI算力芯片研究报告',
					image: '/static/7.jpg',
					author: 'BBQ国际新闻',
					comment: 127,
					time: '10分钟前',
				}]
			}
		},
		onLoad() {

		},
		onShow() {
			this.fetchData()
		},
		methods: {
			go(id) {
				uni.navigateTo({
					url: '/pages/article/detail?id=' + id
				});
			},
			swiperChange(e) {
				this.current = e.detail.current;
			},
			fetchData() {
				var that = this
				uni.request({
					url: 'https://shanghaihuxi.cn/api/index/getArticle',
					method: 'GET',
					header: {
						'Content-Type': 'application/json' // 请求头，可以根据接口要求修改
					},
					success: (res) => {
						that.article = res.data.data.article
						that.banner = res.data.data.banner
						console.log(2222, that.article)
					}
				});
			}

		}
	}
</script>

<style lang="scss" scoped>
	@import "./index.scss";
</style>